namespace C1.Win.C1FlexGrid
{
    using C1.Win.C1FlexGrid.Util.Styles;
    using System;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class C1FlexGrid : C1FlexGridBase
    {
        private AllowMergingEnum _allowMerging = AllowMergingEnum.None;

        internal override void AutoSizeCols(Graphics g, int row1, int col1, int row2, int col2, int extra, AutoSizeFlags flags)
        {
            if (this._allowMerging == AllowMergingEnum.None)
            {
                base.AutoSizeCols(g, row1, col1, row2, col2, extra, flags);
            }
            else
            {
                int num2;
                bool flag = (flags & AutoSizeFlags.IgnoreHidden) != AutoSizeFlags.None;
                bool flag2 = (flags & AutoSizeFlags.IgnoreMerged) != AutoSizeFlags.None;
                bool flag3 = (flags & AutoSizeFlags.SameSize) != AutoSizeFlags.None;
                int num3 = -1;
                for (num2 = col1; num2 <= col2; num2++)
                {
                    if (!flag || (base.Cols[num2].WidthDisplay != 0))
                    {
                        GridTree tree = base._grid._tree;
                        int num4 = tree.TreeWidth(num2);
                        if ((num4 > 0) && ((tree._style & TreeStyleFlags.ButtonBar) != TreeStyleFlags.None))
                        {
                            num3 = (num4 + tree._indent) - extra;
                        }
                        for (int i = row1; i <= row2; i++)
                        {
                            if (!flag || (base.Rows[i].HeightDisplay != 0))
                            {
                                Image image;
                                CheckEnum enum2;
                                string str = base.GetDataDisplay(i, num2, out image, out enum2);
                                if ((image != null) || (str.Length != 0))
                                {
                                    int num5 = this.GetStyleDisplay(i, num2).GetWidth(g, str, image) + num4;
                                    if (this.MergeCell(i, num2))
                                    {
                                        CellRange range = this.GetMergedRange(i, num2, false);
                                        if (flag2 && !range.IsSingleCell)
                                        {
                                            goto Label_012F;
                                        }
                                        num5 /= (range.c2 - range.c1) + 1;
                                    }
                                    if (num5 > num3)
                                    {
                                        num3 = num5;
                                    }
                                Label_012F:;
                                }
                            }
                        }
                        if (!flag3 && (num3 > -1))
                        {
                            base.Cols[num2].Width = num3 + extra;
                            num3 = -1;
                        }
                    }
                }
                if (flag3 && (num3 > -1))
                {
                    for (num2 = col1; num2 <= col2; num2++)
                    {
                        base.Cols[num2].Width = num3 + extra;
                    }
                }
            }
        }

        internal override void AutoSizeRows(Graphics g, int row1, int col1, int row2, int col2, int extra, AutoSizeFlags flags)
        {
            if (this._allowMerging == AllowMergingEnum.None)
            {
                base.AutoSizeRows(g, row1, col1, row2, col2, extra, flags);
            }
            else
            {
                int num2;
                bool flag = (flags & AutoSizeFlags.IgnoreHidden) != AutoSizeFlags.None;
                bool flag2 = (flags & AutoSizeFlags.IgnoreMerged) != AutoSizeFlags.None;
                bool flag3 = (flags & AutoSizeFlags.SameSize) != AutoSizeFlags.None;
                int num = -1;
                for (num2 = row1; num2 <= row2; num2++)
                {
                    if (!flag || (base.Rows[num2].HeightDisplay != 0))
                    {
                        for (int i = col1; i <= col2; i++)
                        {
                            if (!flag || (base.Cols[i].WidthDisplay != 0))
                            {
                                Image image;
                                CheckEnum enum2;
                                string str = base.GetDataDisplay(num2, i, out image, out enum2);
                                if ((image != null) || (str.Length != 0))
                                {
                                    Style styleDisplay = this.GetStyleDisplay(num2, i);
                                    Rectangle rectangle = this.GetCellRectDisplay(num2, i, false, false);
                                    int num4 = styleDisplay.GetHeight(g, rectangle.Width, str, image);
                                    if (this.MergeCell(num2, i))
                                    {
                                        CellRange range = this.GetMergedRange(num2, i, false);
                                        if (flag2 && !range.IsSingleCell)
                                        {
                                            goto Label_0110;
                                        }
                                        num4 /= (range.r2 - range.r1) + 1;
                                    }
                                    if (num4 > num)
                                    {
                                        num = num4;
                                    }
                                Label_0110:;
                                }
                            }
                        }
                        if (!flag3 && (num > -1))
                        {
                            int num5 = num + extra;
                            if (num5 <= base.Rows.DefaultSize)
                            {
                                num5 = -1;
                            }
                            base.Rows[num2].Height = num5;
                            num = -1;
                        }
                    }
                }
                if (flag3 && (num > -1))
                {
                    int num6 = num + extra;
                    if (num6 <= base.Rows.DefaultSize)
                    {
                        num6 = -1;
                    }
                    for (num2 = row1; num2 <= row2; num2++)
                    {
                        base.Rows[num2].Height = num6;
                    }
                }
            }
        }

        internal override int CheckNodeChildren(int row, int col, int level)
        {
            if (!this.MergeCell(row, col))
            {
                return base.CheckNodeChildren(row, col, level);
            }
            CellRange range = this.GetMergedRange(row, col, false);
            row = (base.SubtotalPosition == SubtotalPositionEnum.AboveData) ? range.r2 : range.r1;
            return base.CheckNodeChildren(range.r2, col, level);
        }

        protected override int DrawCell(PaintEventArgs e, int row, int col)
        {
            if (!this.MergeCell(row, col))
            {
                return base.DrawCell(e, row, col);
            }
            CellRange range = this.GetMergedRange(row, col, true);
            if (range.IsSingleCell)
            {
                return base.DrawCell(e, row, col);
            }
            if ((row <= range.r1) || ((row <= base.TopRow) && ((row <= 0) || (row >= base.Rows.Fixed))))
            {
                Image image;
                CheckEnum enum2;
                if ((col > range.c1) && ((col > base.LeftCol) || ((col > 0) && (col < base.Cols.Fixed))))
                {
                    return range.c2;
                }
                Rectangle a = base.GetCellRectDisplay(range.r1, range.c1, true, true);
                Rectangle b = base.GetCellRectDisplay(range.r2, range.c2, true, true);
                Rectangle rc = Rectangle.Union(a, b);
                Rectangle clientRectangle = base.ClientRectangle;
                if (rc.Left > clientRectangle.Right)
                {
                    return range.c2;
                }
                if (!rc.IntersectsWith(e.ClipRectangle) || rc.IsEmpty)
                {
                    return range.c2;
                }
                row = range.r1;
                col = range.c1;
                string str = base.GetDataDisplay(row, col, out image, out enum2);
                Style styleDisplay = this.GetStyleDisplay(row, col);
                this.DrawCell(e.Graphics, row, col, styleDisplay, rc, str, image, enum2);
            }
            return range.c2;
        }

        protected override void DrawRow(PaintEventArgs e, int row)
        {
            if ((base.Cols.Count != 0) && (base.Rows[row].HeightDisplay != 0))
            {
                if (!this.MergeRow(row))
                {
                    base.DrawRow(e, row);
                }
                else
                {
                    int num2;
                    Rectangle cellRect = base._grid.GetCellRect(row, 0);
                    int num = base.Rows.Fixed + base.Rows.Frozen;
                    if (row >= num)
                    {
                        cellRect.Y += base.ScrollPosition.Y;
                    }
                    int bottom = cellRect.Bottom;
                    int num3 = base.Cols.Fixed + base.Cols.Frozen;
                    for (num2 = 0; num2 < num3; num2 = this.DrawCell(e, row, num2) + 1)
                    {
                    }
                    if ((num3 > 0) && (num3 < base.Cols.Count))
                    {
                        cellRect = base._grid.GetCellRect(row, 0);
                        if (row >= num)
                        {
                            cellRect.Y += base.ScrollPosition.Y;
                        }
                        cellRect.Width = base.Cols[num3].Left;
                        base.ExcludeClip(e.Graphics, cellRect);
                    }
                    if ((base.LeftCol > -1) && (base.RightCol > -1))
                    {
                        for (num2 = base.LeftCol; num2 <= base.RightCol; num2 = this.DrawCell(e, row, num2) + 1)
                        {
                        }
                    }
                }
            }
        }

        internal override Rectangle GetCellRectDisplay(int row, int col, bool clipHorz, bool clipVert)
        {
            if ((row < 0) || (col < 0))
            {
                return base.GetCellRectDisplay(row, col, clipHorz, clipVert);
            }
            if (!this.MergeCell(row, col))
            {
                return base.GetCellRectDisplay(row, col, clipHorz, clipVert);
            }
            CellRange range = this.GetMergedRange(row, col, true);
            if (range.IsSingleCell)
            {
                return base.GetCellRectDisplay(row, col, clipHorz, clipVert);
            }
            Rectangle a = base.GetCellRectDisplay(range.r1, range.c1, clipHorz, clipVert);
            Rectangle b = base.GetCellRectDisplay(range.r2, range.c2, clipHorz, clipVert);
            return Rectangle.Union(a, b);
        }

        internal override Rectangle GetCellRectEditor(int row, int col)
        {
            if (this.MergeCell(row, col))
            {
                CellRange range = this.GetMergedRange(row, col, true);
                row = range.r1;
                col = range.c1;
            }
            return base.GetCellRectEditor(row, col);
        }

        protected CellRange GetDefaultMergedRange(CellRange rg, bool clip, bool vert, bool horz)
        {
            int row = rg.r1;
            int col = rg.c1;
            object data = this.GetData(row, col);
            if (!this.IsEmpty(data))
            {
                RowCollection rows = base.Rows;
                if ((vert && this.MergeCol(col)) && !rows[rg.r1].IsNode)
                {
                    int @fixed = rows.Fixed;
                    int num4 = @fixed + rows.Frozen;
                    if (row < @fixed)
                    {
                        rg = this.MergeVert(rg, 0, @fixed - 1, data);
                    }
                    else if (row < num4)
                    {
                        rg = this.MergeVert(rg, @fixed, num4 - 1, data);
                    }
                    else
                    {
                        int min = num4;
                        int max = base.Rows.Count - 1;
                        if (clip)
                        {
                            if (min < base.TopRow)
                            {
                                min = base.TopRow;
                            }
                            if (max > base.BottomRow)
                            {
                                max = base.BottomRow;
                            }
                            if (min > max)
                            {
                                return rg;
                            }
                        }
                        rg = this.MergeVert(rg, min, max, data);
                    }
                    if (((rg.r2 > rg.r1) && (col > base.Cols.Fixed)) && this.RestrictCols())
                    {
                        CellRange range = new CellRange(base._grid, row, col - 1);
                        range = this.GetDefaultMergedRange(range, clip, true, false);
                        if (rg.r1 < range.r1)
                        {
                            rg.r1 = range.r1;
                        }
                        if (rg.r2 > range.r2)
                        {
                            rg.r2 = range.r2;
                        }
                    }
                }
                if (((rg.r1 == rg.r2) && this.MergeRow(row)) && horz)
                {
                    int num7 = base.Cols.Fixed;
                    int num8 = num7 + base.Cols.Frozen;
                    if (col < num7)
                    {
                        rg = this.MergeHorz(rg, 0, num7 - 1, data);
                    }
                    else if (col < num8)
                    {
                        rg = this.MergeHorz(rg, num7, num8 - 1, data);
                    }
                    else
                    {
                        int leftCol = num8;
                        int rightCol = base.Cols.Count - 1;
                        if (clip)
                        {
                            if (leftCol < base.LeftCol)
                            {
                                leftCol = base.LeftCol;
                            }
                            if (rightCol > base.RightCol)
                            {
                                rightCol = base.RightCol;
                            }
                            if (leftCol > rightCol)
                            {
                                return rg;
                            }
                        }
                        rg = this.MergeHorz(rg, leftCol, rightCol, data);
                    }
                    if (((rg.c2 > rg.c1) && (row > base.Rows.Fixed)) && this.RestrictRows())
                    {
                        CellRange range2 = this.GetMergedRange(row - 1, col, clip);
                        if (rg.c1 < range2.c1)
                        {
                            rg.c1 = range2.c1;
                        }
                        if (rg.c2 > range2.c2)
                        {
                            rg.c2 = range2.c2;
                        }
                    }
                }
            }
            return rg;
        }

        public CellRange GetMergedRange(int row, int col)
        {
            return this.GetMergedRange(row, col, false);
        }

        public virtual CellRange GetMergedRange(int row, int col, bool clip)
        {
            CellRange rg = new CellRange(base._grid, row, col);
            if (!this.MergeCol(col) && !this.MergeRow(row))
            {
                return rg;
            }
            if (this.AllowMerging == AllowMergingEnum.Spill)
            {
                return this.GetSpillRange(rg, true);
            }
            if (this.AllowMerging == AllowMergingEnum.Nodes)
            {
                return this.GetSpillRange(rg, false);
            }
            if ((this.AllowMerging == AllowMergingEnum.FixedOnly) && !base._grid.IsCellFixed(row, col))
            {
                return rg;
            }
            return this.GetDefaultMergedRange(rg, clip, true, true);
        }

        private CellRange GetSpillRange(CellRange rg, bool measure)
        {
            int row = rg.r1;
            int col = rg.c1;
            ColumnCollection cols = base.Cols;
            if (this.IsEmpty(row, col))
            {
                if ((col == 0) || (col == cols.Fixed))
                {
                    return rg;
                }
                CellRange cellRange = base.GetCellRange(rg.r1, rg.c1 - 1);
                cellRange = this.GetSpillRange(cellRange, measure);
                if (!cellRange.ContainsCol(col))
                {
                    return rg;
                }
                return cellRange;
            }
            if (cols[col].Visible)
            {
                Style styleDisplay = base._grid.GetStyleDisplay(row, col);
                switch (((AlignHorzEnum) styleDisplay.GetAttribute("AlignHorz")))
                {
                    case AlignHorzEnum.General:
                    {
                        object data = this.GetData(row, col);
                        if (data != null)
                        {
                            Type type = data.GetType();
                            if (type.IsAssignableFrom(typeof(int)) && (type != typeof(object)))
                            {
                                return rg;
                            }
                        }
                        break;
                    }
                    case AlignHorzEnum.Far:
                        return rg;
                }
                int num3 = (col < cols.Fixed) ? (cols.Fixed - 1) : (cols.Count - 1);
                if (num3 <= col)
                {
                    return rg;
                }
                if (!this.IsEmpty(row, col + 1))
                {
                    return rg;
                }
                int num4 = 0x7fffffff;
                if (measure)
                {
                    using (Graphics graphics = base.CreateGraphics())
                    {
                        Image image;
                        CheckEnum enum2;
                        string str = base.GetDataDisplay(row, col, out image, out enum2);
                        num4 = styleDisplay.GetWidth(graphics, str, image);
                    }
                    num4 += base._grid._tree.TreeWidth(col);
                }
                for (int i = cols[col].WidthDisplay; (i < num4) && (rg.c2 < num3); i += cols[rg.c2].WidthDisplay)
                {
                    if (!this.IsEmpty(row, rg.c2 + 1))
                    {
                        return rg;
                    }
                    rg.c2++;
                }
            }
            return rg;
        }

        public override void Invalidate(CellRange rg)
        {
            if (rg.IsValid)
            {
                if (((this._allowMerging == AllowMergingEnum.None) || (rg.c1 < 0)) || (rg.r1 < 0))
                {
                    base.Invalidate(rg);
                }
                else
                {
                    rg.Normalize();
                    bool flag = false;
                    for (int i = rg.r1; (i <= rg.r2) && !flag; i++)
                    {
                        if (!this.GetMergedRange(i, rg.c1, true).IsSingleCell)
                        {
                            flag = true;
                        }
                        if (((rg.c1 != rg.c2) && !flag) && !this.GetMergedRange(i, rg.c2, true).IsSingleCell)
                        {
                            flag = true;
                        }
                    }
                    for (int j = rg.c1 + 1; (j <= (rg.c2 - 1)) && !flag; j++)
                    {
                        if (!this.GetMergedRange(rg.r1, j, true).IsSingleCell)
                        {
                            flag = true;
                        }
                        if (((rg.r1 != rg.r2) && !flag) && !this.GetMergedRange(rg.r2, j, true).IsSingleCell)
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        base.Invalidate();
                    }
                    else
                    {
                        base.Invalidate(rg);
                    }
                }
            }
        }

        internal override bool IsCellCursor(int row, int col)
        {
            bool flag;
            bool flag2;
            if (!this.MergeCell(row, col))
            {
                return base.IsCellCursor(row, col);
            }
            this.ScanRange(row, col, out flag, out flag2);
            return flag2;
        }

        internal override bool IsCellHighlighted(int row, int col)
        {
            bool flag;
            bool flag2;
            if (!this.MergeCell(row, col))
            {
                return base.IsCellHighlighted(row, col);
            }
            if (base.HighLight == HighLightEnum.Never)
            {
                return false;
            }
            if ((base.HighLight == HighLightEnum.WithFocus) && !this.Focused)
            {
                return false;
            }
            if (base._grid.IsCellFixed(row, col))
            {
                return false;
            }
            this.ScanRange(row, col, out flag, out flag2);
            if (flag2)
            {
                if ((base.FocusRect != FocusRectEnum.None) && this.Focused)
                {
                    return false;
                }
                if (base.Editor != null)
                {
                    return false;
                }
            }
            return flag;
        }

        private bool IsEmpty(object o)
        {
            return (((o == null) || (o == DBNull.Value)) || ((o is string) && (((string) o).Length == 0)));
        }

        private bool IsEmpty(int row, int col)
        {
            object data = this.GetData(row, col);
            if (!this.IsEmpty(data))
            {
                return false;
            }
            if (base.GetCellImage(row, col) != null)
            {
                return false;
            }
            return true;
        }

        private bool MergeCell(int row, int col)
        {
            switch (this._allowMerging)
            {
                case AllowMergingEnum.Spill:
                    return true;

                case AllowMergingEnum.Nodes:
                    return base.Rows[row].IsNode;

                case AllowMergingEnum.None:
                    return false;
            }
            if (!base.Rows[row].AllowMerging)
            {
                return base.Cols[col].AllowMerging;
            }
            return true;
        }

        private bool MergeCell(int row, int col, object data)
        {
            object o = this.GetData(row, col);
            if (this.IsEmpty(o) || (data.GetType() != o.GetType()))
            {
                return false;
            }
            if (data is IComparable)
            {
                return (((IComparable) data).CompareTo(o) == 0);
            }
            return data.Equals(o);
        }

        private bool MergeCol(int col)
        {
            switch (this._allowMerging)
            {
                case AllowMergingEnum.Spill:
                case AllowMergingEnum.Nodes:
                    return false;
            }
            if (!base.Cols[col].AllowMerging)
            {
                return false;
            }
            if (((col > base.Cols.Fixed) && this.RestrictCols()) && !this.MergeCol(col - 1))
            {
                return false;
            }
            return true;
        }

        private CellRange MergeHorz(CellRange rg, int min, int max, object data)
        {
            while ((rg.c1 > min) && this.MergeCell(rg.r1, rg.c1 - 1, data))
            {
                CellRange cellRange = base.GetCellRange(rg.r1, rg.c1 - 1);
                cellRange = this.GetDefaultMergedRange(cellRange, true, true, false);
                if (cellRange.r1 != cellRange.r2)
                {
                    break;
                }
                rg.c1--;
            }
            while ((rg.c2 < max) && this.MergeCell(rg.r1, rg.c2 + 1, data))
            {
                CellRange range2 = base.GetCellRange(rg.r1, rg.c2 + 1);
                range2 = this.GetDefaultMergedRange(range2, true, true, false);
                if (range2.r1 != range2.r2)
                {
                    return rg;
                }
                rg.c2++;
            }
            return rg;
        }

        private bool MergeRow(int row)
        {
            if (this._allowMerging != AllowMergingEnum.Spill)
            {
                if ((this._allowMerging == AllowMergingEnum.Nodes) && base.Rows[row].IsNode)
                {
                    return true;
                }
                if (!base.Rows[row].AllowMerging)
                {
                    return false;
                }
                if (((row > base.Rows.Fixed) && this.RestrictRows()) && !this.MergeRow(row - 1))
                {
                    return false;
                }
            }
            return true;
        }

        private CellRange MergeVert(CellRange rg, int min, int max, object data)
        {
            while (((rg.r1 > min) && !base.Rows[rg.r1 - 1].IsNode) && this.MergeCell(rg.r1 - 1, rg.c1, data))
            {
                rg.r1--;
            }
            while (((rg.r2 < max) && !base.Rows[rg.r2 + 1].IsNode) && this.MergeCell(rg.r2 + 1, rg.c1, data))
            {
                rg.r2++;
            }
            return rg;
        }

        internal override void MoveSelection(MoveCursorEnum move, bool extend)
        {
            if (this._allowMerging == AllowMergingEnum.None)
            {
                base.MoveSelection(move, extend);
            }
            else
            {
                CellRange range = base.SelHandler.GetRange();
                int row = extend ? range.r2 : range.r1;
                int col = extend ? range.c2 : range.c1;
                range = this.GetMergedRange(row, col, false);
                switch (move)
                {
                    case MoveCursorEnum.CellPrev:
                        col = range.c1;
                        break;

                    case MoveCursorEnum.CellNext:
                        col = range.c2;
                        break;

                    case MoveCursorEnum.CellUp:
                        row = range.r1;
                        break;

                    case MoveCursorEnum.CellDown:
                        row = range.r2;
                        break;

                    case MoveCursorEnum.CellLeft:
                        col = range.c1;
                        break;

                    case MoveCursorEnum.CellRight:
                        col = range.c2;
                        break;
                }
                this.MoveSelection(move, extend, row, col);
            }
        }

        private bool RestrictCols()
        {
            if (this._allowMerging != AllowMergingEnum.RestrictAll)
            {
                return (this._allowMerging == AllowMergingEnum.RestrictCols);
            }
            return true;
        }

        private bool RestrictRows()
        {
            if (this._allowMerging != AllowMergingEnum.RestrictAll)
            {
                return (this._allowMerging == AllowMergingEnum.RestrictRows);
            }
            return true;
        }

        private void ScanRange(int row, int col, out bool highlight, out bool cursor)
        {
            highlight = false;
            cursor = false;
            CellRange range = this.GetMergedRange(row, col, false);
            row = range.r1;
            while (row <= range.r2)
            {
                col = range.c1;
                while (col <= range.c2)
                {
                    if (base._grid.IsCellSelected(row, col))
                    {
                        highlight = true;
                    }
                    if (base._grid.IsCellCursor(row, col))
                    {
                        cursor = true;
                    }
                    if (highlight && cursor)
                    {
                        break;
                    }
                    col++;
                }
                row++;
            }
        }

        public override void SetCellCheck(int row, int col, CheckEnum check)
        {
            if (!this.MergeCell(row, col))
            {
                base.SetCellCheck(row, col, check);
            }
            else if (base._grid.ShowValueAsCheck(row, col))
            {
                bool data = (check == CheckEnum.Checked) || (check == CheckEnum.TSChecked);
                this.SetData(row, col, data);
            }
            else
            {
                CellRange range = this.GetMergedRange(row, col, false);
                switch (this._allowMerging)
                {
                    case AllowMergingEnum.Spill:
                    case AllowMergingEnum.Nodes:
                        range.c2 = range.c1;
                        break;
                }
                row = range.r1;
                while (row <= range.r2)
                {
                    col = range.c1;
                    while (col <= range.c2)
                    {
                        base._grid.SetCellCheck(row, col, check);
                        col++;
                    }
                    row++;
                }
            }
        }

        public override bool SetData(int row, int col, object data, bool coerce)
        {
            if (!this.MergeCell(row, col))
            {
                return base.SetData(row, col, data, coerce);
            }
            CellRange rg = this.GetMergedRange(row, col, false);
            switch (this._allowMerging)
            {
                case AllowMergingEnum.Spill:
                case AllowMergingEnum.Nodes:
                    rg.c2 = rg.c1;
                    break;
            }
            return base.SetData(rg, data, coerce);
        }

        public bool ShouldSerializeAllowMerging()
        {
            return (this._allowMerging != AllowMergingEnum.None);
        }

        internal override bool StartEditing(int row, int col, char key, bool force)
        {
            if (this.MergeCell(row, col))
            {
                CellRange range = this.GetMergedRange(row, col, false);
                row = range.r1;
                col = range.c1;
            }
            return base.StartEditing(row, col, key, force);
        }

        internal override bool StartEditing(int row, int col, Point ptMouse, bool dblClick)
        {
            if (this.MergeCell(row, col))
            {
                CellRange range = this.GetMergedRange(row, col, false);
                row = range.r1;
                col = range.c1;
            }
            return base.StartEditing(row, col, ptMouse, dblClick);
        }

        public AllowMergingEnum AllowMerging
        {
            get
            {
                return this._allowMerging;
            }
            set
            {
                if (this._allowMerging != value)
                {
                    this._allowMerging = value;
                    base.Invalidate();
                }
            }
        }
    }
}

